   //
//  DataCenter.m
//  CreditManager
//
//  Created by zhl on 2017/8/24.
//  Copyright © 2017年 zhl. All rights reserved.
//

#import "DataCenter.h"
#import "MJExtension.h"

@implementation DataCenter

static DataCenter *_shareInstence = nil;
/**SBDataCenter 单利*/
 + (DataCenter *)shareInstence
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _shareInstence = [[DataCenter alloc] init];
        
    });
    return _shareInstence;
    
}
+ (void)clearValue{
    
    _shareInstence = [[DataCenter alloc] init];
    
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@", [_shareInstence properties_aps]];
}

- (NSDictionary *)properties_aps
{
    NSMutableDictionary *props = [NSMutableDictionary dictionary];
    unsigned int outCount, i;
    objc_property_t *properties = class_copyPropertyList([self class], &outCount);
    for (i = 0; i<outCount; i++)
    {
        objc_property_t property = properties[i];
        const char* char_f =property_getName(property);
        NSString *propertyName = [NSString stringWithUTF8String:char_f];
        id propertyValue = [self valueForKey:(NSString *)propertyName];
        if (propertyValue) [props setObject:propertyValue forKey:propertyName];
    }
    free(properties);
    return props;
}

//将NSDictionary中的Null类型的项目转化成@""
- (NSDictionary *)nullDic:(NSDictionary *)myDic
{
    NSArray *keyArr = [myDic allKeys];
    NSMutableDictionary *resDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < keyArr.count; i ++)
    {
        id obj = [myDic objectForKey:keyArr[i]];
        
        obj = [self changeType:obj];
        
        [resDic setObject:obj forKey:keyArr[i]];
    }
    return resDic;
}

//将NSDictionary中的Null类型的项目转化成@""
- (NSArray *)nullArr:(NSArray *)myArr
{
    NSMutableArray *resArr = [[NSMutableArray alloc] init];
    for (int i = 0; i < myArr.count; i ++)
    {
        id obj = myArr[i];
        
        obj = [self changeType:obj];
        
        [resArr addObject:obj];
    }
    return resArr;
}

//将NSString类型的原路返回
- (NSString *)stringToString:(NSString *)string
{
    return string;
}

//将Null类型的项目转化成@""
- (NSString *)nullToString
{
    return @"";
}

- (id)changeType:(id)myObj
{
    //    SBLog(@"%@", [myObj class]);
    if ([myObj isKindOfClass:[NSDictionary class]])
    {
        return [self nullDic:myObj];
    }
    else if([myObj isKindOfClass:[NSArray class]])
    {
        return [self nullArr:myObj];
    }
    else if([myObj isKindOfClass:[NSString class]])
    {
        return [self stringToString:myObj];
    }
    else if([myObj isKindOfClass:[NSNull class]])
    {
        return [self nullToString];
    }
    else
    {
        return myObj;
    }
}


@end
